package com.me.hippy.sdk.demo.chat;


import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Rect;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;

/* renamed from: com.ailiao.mosheng.commonlibrary.utils.g */
public class KeyboardChangeListener implements ViewTreeObserver.OnGlobalLayoutListener {

    private final Rect visibleDisplayFrame = new Rect();

    private View listenView;

    private int currentKeyboardHeight = -1;

    private C1117a f2317d;

    /* renamed from: com.ailiao.mosheng.commonlibrary.utils.g$a */
    /* compiled from: KeyboardChangeListener */
    public interface C1117a {
        /* renamed from: a */
        void mo14615a(boolean z, int i);
    }

    public KeyboardChangeListener(Activity activity) {
        if (activity == null) {
            Log.e("KeyBoardChangeListener", "activity is null");
            return;
        }
        this.listenView = activity.getWindow().getDecorView();
        this.listenView.getViewTreeObserver().addOnGlobalLayoutListener(this);
    }

    /* renamed from: a */
    public void mo14613a(C1117a aVar) {
        this.f2317d = aVar;
    }

    public void onGlobalLayout() {
        this.listenView.getWindowVisibleDisplayFrame(this.visibleDisplayFrame);
        int height = this.visibleDisplayFrame.height();
        int keyboardHeight = this.listenView.getHeight() - this.visibleDisplayFrame.bottom;
        Log.e("KeyBoardChangeListener", "visibleDecorViewHeight==" + height + " currentKeyboardHeight==" + keyboardHeight);
        if (this.currentKeyboardHeight != keyboardHeight) {
            if (this.f2317d != null) {
                this.f2317d.mo14615a(keyboardHeight - getNavigationBarHeight() > 0, keyboardHeight > 0 ? keyboardHeight : 0);
            }
            this.currentKeyboardHeight = keyboardHeight;
        }
    }

    public static int getNavigationBarHeight() {
        Resources system = Resources.getSystem();
        int identifier = system.getIdentifier("navigation_bar_height", "dimen", "android");
        if (identifier != 0) {
            return system.getDimensionPixelSize(identifier);
        }
        return 0;
    }
}

